package cms.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 功能:
 * Author: yuhui
 * Date: 2021/4/8 17:48
 */
public class InvokeHttp {

    /**
    * 功能描述: 通过反射来进行请求分发
    * @Author: yuhui  2021/4/8 17:52
    */
    public static void invokeReq(Object obj,String MethodName,HttpServletRequest req, HttpServletResponse resp){
        try {
            Method declaredMethod = obj.getClass().getDeclaredMethod(MethodName,HttpServletRequest.class,HttpServletResponse.class);
            declaredMethod.invoke(obj,req,resp);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
